package c15;

public class InterruptSynchronizedDemo {
    private static final Object lock = new Object();

    static class InterruptThread extends Thread {
        final private Object lock;

        public InterruptThread(Object lock) {
            this.lock = lock;
        }
        public void run() {
            synchronized (lock) {
                while(!Thread.currentThread().isInterrupted()) {
                    System.out.println("working...");
                }
                System.out.println("end");
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        synchronized (lock) {
            InterruptThread interruptThread = new InterruptThread(lock);
            interruptThread.start();
            Thread.sleep(100);
            interruptThread.interrupt();
            interruptThread.join();
        }
        System.out.println("main end");
    }
}
